import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
// 状态对象
const state = {
  count: 3
}
// 改变状态变化的方法
const mutations = {
  add(state, n){
    state.count+=n
  },
  reduce(state){
    state.count--
  }
}

/*const getters = {
  count:function (state) {
    return state.count+=10
  }
}*/
const getters = {
  count: state => state.count+=10
}
//增加异步检验
const actions = {
  addAction(context){
    context.commit('add',10) // context上下文对象 相当于store
    setTimeout(()=>{context.commit('reduce')},5000)
    console.log('我比reduce先执行了')
  },
  reduceAction({commit}){ // 传入包装的commit 对象
    commit('reduce')
  }
}
const moduleA ={
  state,mutations,getters,actions
}

export default new Vuex.Store({
modules:{a:moduleA}

})
